package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.entity.dto.activity.ActivityDTO;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author fantuan
 * @created 2025/10/9 10:54
 * @description
 */
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result page(ActivityDTO dto){

        return Result.success(activityService.page(dto));
    }

    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable Integer id) {
        activityService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity) {
        activityService.add(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable Integer id) {
        return Result.success(activityService.getActivityById(id));
    }

    @PutMapping
    public Result updateActivity(@RequestBody Activity activity) {
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result listByType(@PathVariable Integer type) {
        return Result.success(activityService.listByType(type));
    }


}
